var app = getApp()
var https = require('../../utils/https.js')
var auth = require('../../utils/auth.js')

const order = ['red', 'yellow', 'blue', 'green', 'red']

Page({
    data: {
        hot:[],
        // text:"这是一个页面"
        list: [],
        windowHeight: 0,//获取屏幕高度
        imgUrls: [
            '../../images/slide1.jpg',
            '../../images/slide2.jpg',
            '../../images/slide3.jpg',
            '../../images/slide4.jpg'
        ],
        indicatorDots: true,
        autoplay: true,
        interval: 5000,
        duration: 500,
        toView: "red",
        dotCurrent:0,
        newlist:[]
    },
    upper(e) {
        console.log(e)
    },
    lower(e) {
        console.log(e)
    },
    scroll(e) {
      
      console.log(e);
    },
    tap(e) {
        for (let i = 0; i < order.length; ++i) {
            if (order[i] === this.data.toView) {
                this.setData({
                    toView: order[i + 1]
                })
                break
            }
        }
    },
    tapMove(e) {
        this.setData({
            scrollTop: this.data.scrollTop + 10
        })
    },
    onLoad: function (options) {
        var _this = this;
        wx.request({
            url: 'http://www.lwbook.com/index.php/api/test/demo', //仅为示例，并非真实的接口地址
            method : 'GET',
            dataType : 'json',
            data: {},
            header: {
              'content-type': 'application/json' // 默认值
            },
            success (res) {
              _this.setData({
                hot:res.data
              });
            }
          })
        https.get("http://www.lwbook.com/index.php/api/test/demo",
            function (res) {
                that.setData({
                    hotlist : res
                });
            }, function (res) {
                console.info(res);
            });

        https.get("http://www.lwbook.com/index.php/api/test/demo",
            function (res) {
                that.setData({
                    newlist : res
                });
            }, function (res) {
                console.info(res);
            });

        https.get("http://www.lwbook.com/index.php/api/test/demo",
            function (res) {
                that.setData({
                    reclist : res
                });
            }, function (res) {
                console.info(res);
            });
        //获取屏幕高度
        wx.getSystemInfo({
            success: function (res) {
                that.setData({
                    windowHeight: res.windowHeight
                })
            }
        })
        auth.trySettingToken();
    },
    toList: function (e) {
        var show = e.currentTarget.dataset.show;
        wx.navigateTo({
            url: `../list/list?keyword=${e.currentTarget.dataset.cat}&title=${e.currentTarget.dataset.title}&showChoose=${show}`
        });
    },
    //点击事件处理
    clickDetail: function (e) {
        wx.navigateTo({
            url: `../detail/detail?id=${e.currentTarget.dataset.id}&category=${e.currentTarget.dataset.category}&title=${e.currentTarget.dataset.title}`
        });
    },
    onReady: function () {
        // 页面渲染完成
    },
    onShow: function () {
        // 页面显示
    },
    onHide: function () {
        // 页面隐藏
    },
    onUnload: function () {
        // 页面关闭
    },
    //点击事件处理
    bindViewTap: function (e) {
        console.log(e.currentTarget.dataset.id);
    },
    recchange: function(e) {
        this.setData({
            dotCurrent:e.detail.current
        });
    },
    onShareAppMessage: function (res) {
        return {
            title: '',
            path: 'pages/index/index',
            imageUrl:'',
            success: function (shareTickets) {
                console.info(shareTickets + '成功');
                // 转发成功
            },
            fail: function (res) {
                console.log(res + '失败');
                // 转发失败
            },
            complete:function(res){
                // 不管成功失败都会执行
            }
        }
    }
})